package com.pfzy.ui.activity.stroke

import android.graphics.Color
import android.os.Bundle
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.pfzy.ui.R
import com.pfzy.ui.databinding.ActivityMainBinding
import com.pfzy.ui.databinding.ActivityStrokerTextBinding
import com.pfzy.ui.view.strokeText.CustomOutlineSpan

class StrokerTextActivity : AppCompatActivity() {
    private lateinit var mBind: ActivityStrokerTextBinding
    private var topY = 150

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mBind = ActivityStrokerTextBinding.inflate(layoutInflater)
        setContentView(mBind.root)
        initView()
    }

    private fun initView() {
        val spannableString = SpannableString("你好")
        spannableString.setSpan(
            ForegroundColorSpan(Color.BLACK),
            0,
            spannableString.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )
        spannableString.setSpan(
            CustomOutlineSpan(Color.WHITE, 4.0f),
            0,
            spannableString.length,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
        )

        mBind.actStrokerTextTv3.text = spannableString



//        val silentTextView1 = createGradientTextView(
//            "Gradient TextView topToBottom",
//            GradientTextView.topToBottom,
//            animate = false
//        )
//        mBind.root.add .addView(silentTextView1)
//
//        val silentTextView2 = createGradientTextView(
//            "Gradient TextView leftToRight",
//            GradientTextView.leftToRight,
//            animate = false
//        )
//        binding.root.addView(silentTextView2)
//
//        val slowTextView = createGradientTextView(
//            "Gradient TextView Speed: Slow",
//            GradientTextView.leftToRight,
//            GradientTextView.slow
//        )
//        binding.root.addView(slowTextView)
//
//        val normalTextView = createGradientTextView(
//            "Gradient TextView Speed: Normal",
//            GradientTextView.leftToRight,
//            GradientTextView.normal
//        )
//        binding.root.addView(normalTextView)
//
//        val fastTextView = createGradientTextView(
//            "Gradient TextView Speed: Fast",
//            GradientTextView.leftToRight,
//            GradientTextView.fast
//        )
//        binding.root.addView(fastTextView)
    }

//    private fun createGradientTextView(
//        text: String,
//        @AnimateDirection direction: Int,
//        @TranslateSpeed speed: Int = 0,
//        animate: Boolean = true
//    ): GradientTextView {
//        topY += 150
//
//        return GradientTextView(this).apply {
//            layoutParams = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, 100).apply {
//                    topToTop = ConstraintLayout.LayoutParams.PARENT_ID
//                    topMargin = topY
//                    leftMargin = 100
//                }
//            this.text = text
//            this.textSize = 18f
//
//            this.direction = direction
//            this.translateSpeed = speed
//            this.translateAnimate = animate
//
//            setColor(
//                ContextCompat.getColor(this@StrokerTextActivity, R.color.shop_main_color),
//                ContextCompat.getColor(this@StrokerTextActivity, R.color.hint_color_line)
//            )
//        }
//    }
}